package com.insigma.business.qrcode.placement.dto.excel;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.insigma.business.common.utils.ToolsHelper;
import lombok.Getter;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

/**
 * @author max
 * @Description:
 * @date 2024-04-25 15:33
 */
@Getter
public class FlexSelfSubsidyDistrListener  extends AnalysisEventListener<FlexSelfSubsidyDistrInOutDTO> {

    private List<FlexSelfSubsidyDistrInOutDTO> validateNotPassList = new ArrayList<>();

    private List<FlexSelfSubsidyDistrInOutDTO> validatePassList = new ArrayList<>();

    @Override
    public void invoke(FlexSelfSubsidyDistrInOutDTO importDTO, AnalysisContext analysisContext) {
        if(ToolsHelper.isEmpty(importDTO)){
            return;
        }
        StringBuilder failRes = new StringBuilder();
        if(ToolsHelper.isEmpty(importDTO.getPsnName())){
            failRes.append("||姓名为空;");
        }
        if(ToolsHelper.isEmpty(importDTO.getIdCardNum())){
            failRes.append("||证件号码为空;");
        }
        if(importDTO.getIdCardNum().length() != 18 && importDTO.getIdCardNum().length() != 15 ){
            failRes.append("||证件号码有误;");
        }
        if(ToolsHelper.isEmpty(importDTO.getAdmdvs())){
            failRes.append("||安置地为空;");
        }
        if(ToolsHelper.isEmpty(importDTO.getPayYear())){
            failRes.append("||年份为空;");
        }
        if(importDTO.getPayYear().length() != 4){
            failRes.append("||年份长度有误;");
        }
        if(ToolsHelper.isEmpty(importDTO.getBankAcctName())){
            failRes.append("||银行账户名称为空;");
        }
        if(ToolsHelper.isEmpty(importDTO.getBankAcctName())){
            failRes.append("||银行账号为空;");
        }
        if(ToolsHelper.isEmpty(importDTO.getBankAddr())){
            failRes.append("||开户行地址为空;");
        }
        if(ToolsHelper.isEmpty(importDTO.getPayAmt()) || BigDecimal.ZERO.compareTo(importDTO.getPayAmt()) == 0){
            failRes.append("||发放金额为空;");
        }
        if(ToolsHelper.isEmpty(importDTO.getPayTime())){
            failRes.append("||发放时间为空;");
        }

        if(failRes.length() == 0){
            validatePassList.add(importDTO);
        }else {
            importDTO.setMemo((ToolsHelper.isEmpty(importDTO.getMemo()) ? "" : importDTO.getMemo()) + failRes.toString());
            validateNotPassList.add(importDTO);
        }
    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {}
}
